<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :sm="24" :md="12" :xl="8">
            <a-form-item label="用户手机">
              <a-input placeholder="请输入" v-model="queryParam.wechatMobile"></a-input>
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="12" :xl="8">
            <a-form-item label="微信昵称">
              <a-input placeholder="请输入" v-model="queryParam.wechatName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :sm="24" :md="12" :xl="8">
            <a-form-item label="订单号">
              <a-input placeholder="请输入" v-model="queryParam.orderId"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :sm="24" :md="12" :xl="8">
              <a-form-item label="是否显示">
                <j-dict-select-tag allowClear v-model="queryParam.display" placeholder="请选择" dictCode="userYn" />
              </a-form-item>
            </a-col>
            <a-col :sm="24" :md="12" :xl="8">
              <a-form-item label="创建时间">
                <a-range-picker allowClear class="per100" v-model="tempTimes" @change="timeChange" />
              </a-form-item>
            </a-col>
          </template>

          <a-col :sm="24" :md="12" :xl="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button @click="searchReset()" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- table区域 -->
    <a-table
      ref="table"
      bordered
      size="middle"
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      :scroll="{ x: 1200 }"
      @change="handleTableChange"
    >
      <span slot="orderOrigin" slot-scope="text, record">
        <a-tag color="#1890FF" v-if="text === '0'">
          {{ filterDictText(orderOriginOptions, text) }}
        </a-tag>
        <a-tag color="#04de6d" v-else-if="text === '1'">
          {{ filterDictText(orderOriginOptions, text) }}
        </a-tag>
        <a-tag color="#000" v-else-if="text === '3'">
          {{ filterDictText(orderOriginOptions, text) }}
        </a-tag>
        <a-tag color="#722ed1" v-else-if="text === '2'">
          {{ filterDictText(orderOriginOptions, text) }}
        </a-tag>
      </span>
    </a-table>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { initDictOptions, filterDictText } from '@/components/dict/JDictSelectUtil'
import Api from '@/api/MemberManage/RechargeRecord'
import { formatAmountFromFenToYuan } from '@/utils/util'

export default {
  name: 'RechargeRecord',
  mixins: [JeecgListMixin],
  data() {
    return {
      filterDictText,
      url: {
        list: Api.list
      },
      columns: [],
      orderStatusOptions: [],
      orderOriginOptions: [],
      hiddenOptions: []
    }
  },
  created() {
    this.columns = [
      {
        title: '充值订单号',
        align: 'center',
        dataIndex: 'rechargeId',
        sorter: (a, b) => {
          return a.rechargeId - b.rechargeId
        }
      },
      {
        title: '用户/微信昵称',
        align: 'center',
        dataIndex: 'wechatName'
      },
      {
        title: '充值金额',
        dataIndex: 'amount',
        align: 'center',
        customRender: (text, record, index) => {
          return formatAmountFromFenToYuan(text)
        },
        sorter: (a, b) => {
          return a.amount - b.amount
        }
      },
      {
        title: '订单号',
        align: 'center',
        dataIndex: 'orderId',
        sorter: (a, b) => {
          return a.orderId - b.orderId
        }
      },
      {
        title: '订单来源',
        dataIndex: 'orderOrigin',
        align: 'center',
        scopedSlots: { customRender: 'orderOrigin' },
        sorter: (a, b) => {
          return a.orderOrigin - b.orderOrigin
        }
      },
      {
        title: '订单状态',
        dataIndex: 'status',
        align: 'center',
        customRender: (text, record, index) => {
          //字典值替换通用方法
          return filterDictText(this.orderStatusOptions, text)
        },
        sorter: (a, b) => {
          return a.status - b.status
        }
      },
      {
        title: '是否隐藏',
        dataIndex: 'display',
        align: 'center',
        customRender: (text, record, index) => {
          //字典值替换通用方法
          return filterDictText(this.hiddenOptions, text)
        },
        sorter: (a, b) => {
          return a.display - b.display
        }
      },
      {
        title: '创建时间',
        align: 'center',
        dataIndex: 'createTime',
        sorter: (a, b) => {
          return a.createTime - b.createTime
        }
      }
    ]
  },
  methods: {
    // 初始化数据字典
    initDictConfig() {
      //初始化字典 - 订单状态
      initDictOptions('orderStatus').then(res => {
        if (res.success) {
          this.orderStatusOptions = res.result
        }
      })
      //初始化字典 - 订单来源
      initDictOptions('orderOrigin').then(res => {
        if (res.success) {
          this.orderOriginOptions = res.result
        }
      })
      initDictOptions('hidden').then(res => {
        if (res.success) {
          this.hiddenOptions = res.result
        }
      })
    },
    // 创建时间改变
    timeChange(e, arr) {
      if (arr[0]) {
        this.queryParam.startTime = arr[0]
        this.queryParam.endTime = arr[1]
      } else {
        this.queryParam.startTime = undefined
        this.queryParam.endTime = undefined
      }
    }
  }
}
</script>

<style scoped></style>

